<template>
  <div class="CreateOrEditRole">
    <el-form
      ref="form"
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      :rules="rules"
    >
      <el-form-item prop="name" label="角色名称">
        <el-input v-model="formInline.name" placeholder="角色名称"></el-input>
      </el-form-item>
      <el-form-item prop="code" label="角色编码">
        <el-input v-model="formInline.code" placeholder="角色编码"></el-input>
      </el-form-item>
      <el-form-item prop="description" label="角色描述">
        <el-input
          v-model="formInline.description"
          placeholder="角色描述"
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { saveOrUpdateRole } from '../api/index'
export default Vue.extend({
  name: 'CreateOrEditRole',
  data () {
    return {
      formInline: {
        id: null,
        name: '',
        code: '',
        description: ''
      },
      rules: {
        name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
        code: [{ required: true, message: '请输入角色编码', trigger: 'blur' }],
        description: [
          { required: true, message: '请输入角色描述', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async saveOrUpdateRole () {
      const { data } = await saveOrUpdateRole(this.formInline)
      console.log(data)
      if (data.code === '000000') {
        this.$message.success('提交成功')
      } else {
        this.$message.error('保存失败')
      }
    }
  }
})
</script>

<style lang="scss" scoped></style>
